<template><div><h2 id="laravel-valet" tabindex="-1"><a class="header-anchor" href="#laravel-valet"><span>Laravel Valet</span></a></h2>
<ul>
<li><a href="#introduction">简介</a></li>
<li><a href="#installation">安装</a>
<ul>
<li><a href="#upgrading-valet">升级</a></li>
</ul>
</li>
<li><a href="#serving-sites">服务站点</a>
<ul>
<li><a href="#the-park-command">Park 命令</a></li>
<li><a href="#the-link-command">Link 命令</a></li>
<li><a href="#securing-sites">使用 TLS 保护站点</a></li>
<li><a href="#serving-a-default-site">服务默认站点</a></li>
<li><a href="#per-site-php-versions">默认 PHP 版本</a></li>
</ul>
</li>
<li><a href="#sharing-sites">共享站点</a>
<ul>
<li><a href="#sharing-sites-via-ngrok">通过 Ngrok 共享站点</a></li>
<li><a href="#sharing-sites-via-expose">通过 Expose 共享站点</a></li>
<li><a href="#sharing-sites-on-your-local-network">共享本地网络站点</a></li>
</ul>
</li>
<li><a href="#site-specific-environment-variables">网站特定环境变量</a></li>
<li><a href="#proxying-services">代理服务</a></li>
<li><a href="#custom-valet-drivers">自定义 Valet 驱动</a>
<ul>
<li><a href="#local-drivers">本地驱动</a></li>
</ul>
</li>
<li><a href="#other-valet-commands">其他 Valet 命令</a></li>
<li><a href="#valet-directories-and-files">Valet 目录和文件</a>
<ul>
<li><a href="#disk-access">磁盘访问</a></li>
</ul>
</li>
</ul>
<h2 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h2>
<p><a href="https://github.com/laravel/valet" target="_blank" rel="noopener noreferrer">Laravel Valet</a> 是一个面向 macOS 极简主义者的 Laravel 开发环境。Laravel Valet 为你的 Mac 设置了开机后始终在后台运行 <a href="https://www.nginx.com/" target="_blank" rel="noopener noreferrer">Nginx</a> 服务。然后，使用 <a href="https://en.wikipedia.org/wiki/Dnsmasq" target="_blank" rel="noopener noreferrer">DnsMasq</a> 将所有指向安装在本地的计算机站点请求代理到 <code v-pre>*.test</code> 结尾的域名上。</p>
<p>总之，Valet 是一个速度极快的 Laravel 开发环境，仅仅占用了 7 MB 内存。Valet 并不能完全取代 <a href="https://learnku.com/docs/laravel/10.x/sail" target="_blank" rel="noopener noreferrer">Sail</a> 或 <a href="https://learnku.com/docs/laravel/10.x/homestead" target="_blank" rel="noopener noreferrer">Homestead</a>，只是提供了另外一种使用起来更加灵活、方便、以及内存占用更小的选择。</p>
<p>开箱即用，Valet 支持但不局限于以下内容：</p>
<ul>
<li><a href="https://laravel.com/" target="_blank" rel="noopener noreferrer">Laravel</a></li>
<li><a href="https://roots.io/bedrock/" target="_blank" rel="noopener noreferrer">Bedrock</a></li>
<li><a href="https://cakephp.org/" target="_blank" rel="noopener noreferrer">CakePHP 3</a></li>
<li><a href="https://www.concretecms.com/" target="_blank" rel="noopener noreferrer">ConcreteCMS</a></li>
<li><a href="https://contao.org/en/" target="_blank" rel="noopener noreferrer">Contao</a></li>
<li><a href="https://craftcms.com/" target="_blank" rel="noopener noreferrer">Craft</a></li>
<li><a href="https://www.drupal.org/" target="_blank" rel="noopener noreferrer">Drupal</a></li>
<li><a href="https://www.expressionengine.com/" target="_blank" rel="noopener noreferrer">ExpressionEngine</a></li>
<li><a href="https://jigsaw.tighten.co/" target="_blank" rel="noopener noreferrer">Jigsaw</a></li>
<li><a href="https://www.joomla.org/" target="_blank" rel="noopener noreferrer">Joomla</a></li>
<li><a href="https://github.com/themsaid/katana" target="_blank" rel="noopener noreferrer">Katana</a></li>
<li><a href="https://getkirby.com/" target="_blank" rel="noopener noreferrer">Kirby</a></li>
<li><a href="https://magento.com/" target="_blank" rel="noopener noreferrer">Magento</a></li>
<li><a href="https://octobercms.com/" target="_blank" rel="noopener noreferrer">OctoberCMS</a></li>
<li><a href="https://sculpin.io/" target="_blank" rel="noopener noreferrer">Sculpin</a></li>
<li><a href="https://www.slimframework.com/" target="_blank" rel="noopener noreferrer">Slim</a></li>
<li><a href="https://statamic.com/" target="_blank" rel="noopener noreferrer">Statamic</a></li>
<li>Static HTML</li>
<li><a href="https://symfony.com/" target="_blank" rel="noopener noreferrer">Symfony</a></li>
<li><a href="https://wordpress.org/" target="_blank" rel="noopener noreferrer">WordPress</a></li>
<li><a href="https://framework.zend.com/" target="_blank" rel="noopener noreferrer">Zend</a></li>
</ul>
<p>但是，你可以使用自己的 <a href="#custom-valet-drivers">自定义驱动程序</a> 扩展 Valet 。 .</p>
<h2 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h2>
<blockquote>
<p>注意：Valet 需要 macOS 和 <a href="https://brew.sh/" target="_blank" rel="noopener noreferrer">Homebrew</a> ，你应该确保没有其他程序 (例如 Apache 或者 Nginx) 占用本地计算机的 80 端口。</p>
</blockquote>
<p>首先，你首先需要使用以下 <code v-pre>update</code> 命令确保 Homebrew 是最新的：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">brew update</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>接下来，你应该使用 Homebrew 安装 PHP:</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">brew <span class="token function">install</span> php</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>在安装 PHP 之后，就可以安装 <a href="https://getcomposer.org/" target="_blank" rel="noopener noreferrer">Composer 软件包管理器</a> 了。 另外，你应该确保 <code v-pre>~/.composer/vendor/bin</code> 目录位于系统的「PATH」 中。安装 Composer 之后，你可以将 Laravel Valet 安装为全局 Composer 软件包：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> global require laravel/valet</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>最后，你可以执行 Valet 的 <code v-pre>install</code> 命令。这将配置并安装 Valet 和 DnsMasq。此外，Valet 依赖的守护程序将配置为在系统启动时启动：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet <span class="token function">install</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>安装 Valet 后，请尝试使用如 之类的命令 <code v-pre>ping foobar.test</code> ping 终端上的任何 <code v-pre>*.test</code> 域。 如果 Valet 安装正确，你应该看到该域在 <code v-pre>127.0.0.1</code> 上响应。</p>
<p>每当你的机器启动时，Valet 将自动启动其所需的相关服务。</p>
<h4 id="php-版本" tabindex="-1"><a class="header-anchor" href="#php-版本"><span>PHP 版本</span></a></h4>
<blockquote>
<p>注意：你无需修改全局的 PHP 版本，你可以通过 <code v-pre>isolate</code> <a href="#per-site-php-versions">命令</a>指定 Valet 使用每个站点的 PHP 版本</p>
</blockquote>
<p>Valet 允许你使用 <code v-pre>valet use php@version</code> 命令切换 PHP 版本。如果尚未安装， Valet 将通过 Homebrew 安装指定的 PHP 版本：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet use php@8.1</span>
<span class="line"></span>
<span class="line">valet use php</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>你还可以在项目的根目录中创建一个 <code v-pre>.valetphprc</code> 文件。 <code v-pre>.valetphprc</code> 文件应包含站点应使用的PHP版本：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php@8.1</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>创建此文件后，你只需执行 <code v-pre>valet use</code> 命令，命令将通过读取文件来确定站点的首选PHP版本。</p>
<blockquote>
<p><strong>注意</strong><br>
Valet一次仅提供一个PHP版本，即使你安装了多个PHP版本。</p>
</blockquote>
<h4 id="数据库" tabindex="-1"><a class="header-anchor" href="#数据库"><span>数据库</span></a></h4>
<p>如果应用程序需要数据库，请查看<a href="https://dbngin.com/" target="_blank" rel="noopener noreferrer">DBngin</a>，它提供了一个免费的全合一数据库管理工具，包括MySQL、PostgreSQL和Redis。安装DBngin后，你可以使用<code v-pre>root</code>用户名和空字符串作为密码连接到你的数据库<code v-pre>127.0.0.1</code>。</p>
<h4 id="重置安装" tabindex="-1"><a class="header-anchor" href="#重置安装"><span>重置安装</span></a></h4>
<p>如果你无法使Valet安装正常运行，请执行<code v-pre>composer global require laravel/valet</code>命令，然后执行<code v-pre>valet install</code>将重置你的安装并可以解决各种问题。在极少数情况下，可能需要通过执行<code v-pre>valet uninstall --force</code>，然后执行<code v-pre>valet install</code>来进行“硬重置”Valet。</p>
<h3 id="升级-valet" tabindex="-1"><a class="header-anchor" href="#升级-valet"><span>升级 Valet</span></a></h3>
<p>你可以通过在终端中执行<code v-pre>composer global require laravel/valet</code>命令来更新Valet安装。升级后，建议运行<code v-pre>valet install</code>命令，以便Valet可以根据需要对你的配置文件进行其他升级。</p>
<h2 id="运行站点服务" tabindex="-1"><a class="header-anchor" href="#运行站点服务"><span>运行站点服务</span></a></h2>
<p>安装Valet后，你可以开始为你的Laravel应用程序提供服务。Valet提供了两个命令来帮助你服务你的应用程序： <code v-pre>park</code> 和 <code v-pre>link</code> 。</p>
<h3 id="park-命令" tabindex="-1"><a class="header-anchor" href="#park-命令"><span><code v-pre>park</code> 命令</span></a></h3>
<p><code v-pre>park</code> 命令在你的电脑上注册一个包含应用程序的目录。 一旦该目录被 Valet「parked」，该目录下所有应用都可以使用 <code v-pre>http://文件夹名.test</code> 来访问：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites</span>
<span class="line"></span>
<span class="line">valet park</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>这就是所有需要手动的操作。现在，任何你创建在「parked」目录中的应用都可以使用 <code v-pre>http://文件夹名.test</code> 域名访问。例如，如果你的「parked」路径下包括一个名为「laravel」的目录，可以使用 <code v-pre>http://laravel.test</code> 来访问。此外，Valet 自动允许二级域名访问此站点。 (<code v-pre>http://foo.laravel.test</code>)。</p>
<h3 id="link-命令" tabindex="-1"><a class="header-anchor" href="#link-命令"><span><code v-pre>link</code> 命令</span></a></h3>
<p>该 <code v-pre>link</code> 命令也可以用来为你的 Laravel 站点提供服务。如果要为目录中的单个站点而不是整个目录提供服务，则此命令非常有用。</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">valet <span class="token function">link</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>使用 <code v-pre>link</code> 命令链接一个站点后，你可以使用目录名称来访问。例如，你可以在浏览器中通过 <code v-pre>http://laravel.test</code> 访问。另外，Valet 自动添加了站点二级目录的访问功能，例如 (<code v-pre>http://foo.laravel.test</code>)。</p>
<p>如果你想要使用不同的域名来访问相同站点，你可以使用 <code v-pre>link</code> 命令来构造站点。例如，你可以使用以下命令来指定域名 <code v-pre>http://application.test</code> ：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">valet <span class="token function">link</span> application</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>当然，你也可以使用 <code v-pre>link</code> 命令来设置子域名访问：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet <span class="token function">link</span> api.application</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>你可以使用 <code v-pre>links</code> 命令来查看所有的目录链接：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet links</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p><code v-pre>unlink</code> 命令可以用来删除目录链接：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">valet unlink</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="使用-tls-保护站点" tabindex="-1"><a class="header-anchor" href="#使用-tls-保护站点"><span>使用 TLS 保护站点</span></a></h3>
<p>默认情况下，Valet 使用 HTTP 协议提供服务。当然，如果你想使用 HTTP/2 通过 TLS 加密你的站点，你可以使用 <code v-pre>secure</code> 命令。例如， 如果你的站点由 <code v-pre>laravel.test</code> 域名的 Valet 提供服务，可以使用以下命令为站点实现安全保护功能：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet secure laravel</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>要 「解除保护」并恢复 HTTP 访问 ，请使用 <code v-pre>unsecure</code> 命令。像 <code v-pre>secure</code> 命令一样，该命令接受你想要解除保护的主机名：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet unsecure laravel</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="默认站点" tabindex="-1"><a class="header-anchor" href="#默认站点"><span>默认站点</span></a></h3>
<p>有时，当访问未知的 <code v-pre>test</code> 域时，你可能希望访问「默认」站点，而不是 <code v-pre>404</code> 。要实现这一点，你可以在 <code v-pre>~/.config/valet/config.json</code> 配置文件中添加一个 <code v-pre>default</code> 选项。 并设置默认站点的路径：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string double-quoted-string">"default"</span><span class="token punctuation">:</span> <span class="token string double-quoted-string">"/Users/Sally/Sites/example-site"</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="站点-php-版本" tabindex="-1"><a class="header-anchor" href="#站点-php-版本"><span>站点 PHP 版本</span></a></h3>
<p>默认情况下，Valet 使用你的全局 PHP 安装来为你的站点提供服务。 但是，如果你需要跨多个站点支持多个 PHP 版本，则可以使用 <code v-pre>isolate</code> 命令指定特定站点的 PHP 版本。 <code v-pre>isolate</code> 命令将 Valet 配置为当前工作目录的站点使用指定的 PHP 版本：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/example-site</span>
<span class="line"></span>
<span class="line">valet isolate php@8.0</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你的站点名称与目录名称不一致，你可以使用 <code v-pre>--site</code> 选项指定站点名称：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet isolate php@8.0 <span class="token parameter variable">--site</span><span class="token operator">=</span><span class="token string">"site-name"</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>为方便起见，你可以使用 <code v-pre>valet php</code>、<code v-pre>composer</code> 和 <code v-pre>which-php</code> 命令根据站点配置的 PHP 版本代理对适合的 PHP CLI 或工具的调用：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet php</span>
<span class="line">valet <span class="token function">composer</span></span>
<span class="line">valet which-php</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>你可以执行 <code v-pre>isolated</code> 命令来显示所有隔离站点及其 PHP 版本的列表：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet isolated</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>要将站点恢复为 Valet 全局安装的 PHP 版本，你可以从站点的根目录调用 <code v-pre>unisolate</code> 命令：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet unisolate</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="共享站点" tabindex="-1"><a class="header-anchor" href="#共享站点"><span>共享站点</span></a></h2>
<p>Valet 甚至包含了一个与全世界共享你的本地站点的命令，提供了一种在移动设备上测试你的站点或与团队成员和客户共享的简单方法。</p>
<h3 id="使用-ngrok-共享站点" tabindex="-1"><a class="header-anchor" href="#使用-ngrok-共享站点"><span>使用 Ngrok 共享站点</span></a></h3>
<p>要共享站点，请在终端中进到站点目录，并运行 <code v-pre>valet share</code> 命令。一个公开可访问的 URL 将会插入到你的剪贴板中，你可以分享给团队成员或在浏览器中打开它:</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">valet share</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>要停止共享你的站点，可以按 <code v-pre>Control + C</code> 。使用 Ngrok 共享你的网站需要你 <a href="https://dashboard.ngrok.com/signup" target="_blank" rel="noopener noreferrer">创建一个 Ngrok 帐户</a> 和 <a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank" rel="noopener noreferrer">设置身份验证令牌</a>。</p>
<blockquote>
<p><strong>提示</strong><br>
你可以向 share 命令传递额外的参数， 如 <code v-pre>valet share --region=eu</code>。 详细信息，请参考 <a href="https://ngrok.com/docs" target="_blank" rel="noopener noreferrer">ngrok 文档</a>。</p>
</blockquote>
<h3 id="通过-expose-共享网站" tabindex="-1"><a class="header-anchor" href="#通过-expose-共享网站"><span>通过 Expose 共享网站</span></a></h3>
<p>如果你已经安装了 <a href="https://expose.dev/" target="_blank" rel="noopener noreferrer">Expose</a>，你可以在终端里进入网站目录运行 <code v-pre>expose</code> 命令来共享你的网站。可以访问 <a href="https://expose.dev/docs" target="_blank" rel="noopener noreferrer">Expose 文档</a> 查看命令行参数说明。共享网站后，Expose 将显示共享 URL，你可以在其他设备或团队成员之间使用它：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">expose</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>你可以按下 <code v-pre>Control + C</code> 停止共享网站。</p>
<h3 id="在局域网里共享网站" tabindex="-1"><a class="header-anchor" href="#在局域网里共享网站"><span>在局域网里共享网站</span></a></h3>
<p>Valet 默认限制本机 <code v-pre>127.0.0.1</code> 访问，以便你的开发机器不会受到来自互联网的安全风险。</p>
<p>如果你想让局域网里的其他设备通过你的局域网 IP 地址访问 Valet 网站（例如：<code v-pre>192.168.1.10/application.test</code>），则需要手动编辑该网站的 Nginx 配置文件，删除 <code v-pre>listen</code> 指令上的限制。你需要删除端口 80 和 443 的 <code v-pre>listen</code> 指令前缀 <code v-pre>127.0.0.1：</code>。</p>
<p>如果你没有在项目上运行 <code v-pre>valet secure</code>，则可以通过编辑 <code v-pre>/usr/local/etc/nginx/valet/valet.conf</code> 文件来为所有非 HTTPS 网站打开网络访问。但是，如果你通过 HTTPS 提供项目站点（即你已经对站点运行了 <code v-pre>valet secure</code>），则应编辑 <code v-pre>~/.config/valet/Nginx/app-name.test</code> 文件。</p>
<p>更新了 Nginx 配置后，需要运行 <code v-pre>valet restart</code> 命令让配置更改生效。</p>
<h2 id="站点特定环境变量" tabindex="-1"><a class="header-anchor" href="#站点特定环境变量"><span>站点特定环境变量</span></a></h2>
<p>一些使用其他框架的应用程序可能依赖于服务器环境变量，但不提供在你的项目中配置这些变量的方法。 Valet 允许你通过在项目根目录内添加 <code v-pre>.valet-env.php</code> 文件来配置站点特定环境变量。此文件应返回一个站点 / 环境变量对数组，该数组将添加到数组中指定的每个站点的全局 <code v-pre>$_SERVER</code> 数组中：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token comment">// 将 laravel.test 站点的 $_SERVER['key'] 设置为 "value"...</span></span>
<span class="line">    <span class="token string single-quoted-string">'laravel'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'value'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// 将所有站点的 $_SERVER['key'] 设置为 "value"...</span></span>
<span class="line">    <span class="token string single-quoted-string">'*'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'value'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="代理服务" tabindex="-1"><a class="header-anchor" href="#代理服务"><span>代理服务</span></a></h2>
<p>有时你可能希望将 Valet 域名代理到本地计算机上的另一项服务。 例如，你可能偶尔需要运行 Valet，同时在 Docker 中运行单独的站点； 但是， Valet 和 Docker 不能同时绑定到80端口。</p>
<p>为了解决这个问题，你可以用 <code v-pre>proxy</code> 命令去生成一个代理。例如，你可以代理所有流量从 <code v-pre>http://elasticsearch.test</code> 到 <code v-pre>http://127.0.0.1:9200</code>：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token comment"># 通过 HTTP 代理...</span></span>
<span class="line">valet proxy elasticsearch http://127.0.0.1:9200</span>
<span class="line"></span>
<span class="line"><span class="token comment"># 通过 TLS + HTTP/2 代理...</span></span>
<span class="line">valet proxy elasticsearch http://127.0.0.1:9200 <span class="token parameter variable">--secure</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>你可以用 <code v-pre>unproxy</code> 命令去删除一个代理：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet unproxy elasticsearch</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>你可以用 <code v-pre>proxies</code> 命令列出所有被代理的站点配置：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet proxies</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="定制-valet-驱动" tabindex="-1"><a class="header-anchor" href="#定制-valet-驱动"><span>定制 Valet 驱动</span></a></h2>
<p>你可以编写自己的 Valet「驱动」来为在 Valet 本身不支持的框架或 CMS 上运行的 PHP 应用程序提供服务。安装 Valet 时，创建了一个 <code v-pre>~/.config/valet/Drivers</code> 目录，其中包含一个 <code v-pre>SampleValetDriver.php</code> 文件。该文件包含一个示例驱动程序实现，用于演示如何编写自定义驱动程序。编写驱动只需要你实现三种方法： <code v-pre>serves</code> ， <code v-pre>isStaticFile</code> ， 和 <code v-pre>frontControllerPath</code>。</p>
<p>这三种方法都接收 <code v-pre>$sitePath</code>, <code v-pre>$siteName</code>, 和 <code v-pre>$uri</code> 值作为其参数。 <code v-pre>$sitePath</code> 是你机器上服务的网站的完整的路径， 如 <code v-pre>/Users/Lisa/Sites/my-project</code>。 <code v-pre>$siteName</code> 是 「host」/「site name」域名的一部分 (<code v-pre>my-project</code>)。<code v-pre>$uri</code> 是传入的请求 URI (<code v-pre>/foo/bar</code>)。</p>
<p>完成你的自定义 Valet 驱动后，使用 <code v-pre>frameworkvaletdriver.php</code> 命名约定将它放在<code v-pre>~/.config/valet/Drivers</code> 目录中。 例如，如果你正在为 WordPress 编写自定义 Valet 驱动，则文件名应为 <code v-pre>WordPressValetDriver.php</code>。</p>
<p>我们来看看自定义的 Valet 驱动程序应该实现的每种方法的示例实现。</p>
<h4 id="serves-方法" tabindex="-1"><a class="header-anchor" href="#serves-方法"><span><code v-pre>serves</code> 方法</span></a></h4>
<p>如果驱动程序应该处理传入的请求，<code v-pre>serves</code> 方法应该返回 <code v-pre>true</code>。否则，该方法应返回 <code v-pre>false</code>。因此，在这个方法中，你应该尝试确定给定的<code v-pre>$sitePath</code> 是否包含你试图服务的类型的项目。</p>
<p>例如，假设我们正在编写一个 <code v-pre>WordPressValetDriver</code>。我们的 <code v-pre>serves</code> 方法可能看起来如下所示：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 确定驱动程序是否为请求服务。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$sitePath</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$siteName</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$uri</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">bool</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">serves</span><span class="token punctuation">(</span><span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token variable">$uri</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token function">is_dir</span><span class="token punctuation">(</span><span class="token variable">$sitePath</span><span class="token operator">.</span><span class="token string single-quoted-string">'/wp-admin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="isstaticfile-方法" tabindex="-1"><a class="header-anchor" href="#isstaticfile-方法"><span><code v-pre>isStaticFile</code> 方法</span></a></h4>
<p><code v-pre>isStaticFile</code> 应当确定即将到来的请求是否针对一个「静态」文件，比如：图片和样式表。如果文件是静态的，此方法应当返回静态文件在磁盘上的完全限定路径。如果即将到来的请求不是针对一个静态文件，这个方法应当返回 <code v-pre>false</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 确定传入请求是否针对静态文件。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$sitePath</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$siteName</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$uri</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">string</span><span class="token punctuation">|</span><span class="token keyword">false</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">isStaticFile</span><span class="token punctuation">(</span><span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token variable">$uri</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">file_exists</span><span class="token punctuation">(</span><span class="token variable">$staticFilePath</span> <span class="token operator">=</span> <span class="token variable">$sitePath</span><span class="token operator">.</span><span class="token string single-quoted-string">'/public/'</span><span class="token operator">.</span><span class="token variable">$uri</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$staticFilePath</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">return</span> <span class="token constant boolean">false</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p><strong>注意</strong><br>
仅当 <code v-pre>serves</code> 方法对传入请求返回 <code v-pre>true</code> 且请求 URI 不是 <code v-pre>/</code> 时，才会调用 <code v-pre>isStaticFile</code> 方法。</p>
</blockquote>
<h4 id="frontcontrollerpath-方法" tabindex="-1"><a class="header-anchor" href="#frontcontrollerpath-方法"><span><code v-pre>frontControllerPath</code> 方法</span></a></h4>
<p><code v-pre>frontControllerPath</code> 方法应该返回你的应用的「前端控制器」的完全限定路径，它通常是 「index.php」 或等效的文件：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 获取应用程序前端控制器的完全解析路径。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$sitePath</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$siteName</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$uri</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">string</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">frontControllerPath</span><span class="token punctuation">(</span><span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token variable">$uri</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token variable">$sitePath</span><span class="token operator">.</span><span class="token string single-quoted-string">'/public/index.php'</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="本地驱动" tabindex="-1"><a class="header-anchor" href="#本地驱动"><span>本地驱动</span></a></h3>
<p>如果你想要为单个应用自定义一个 Valet 驱动，请在应用根目录创建一个 <code v-pre>LocalValetDriver.php</code> 文件。你的自定义驱动可以继承 <code v-pre>ValetDriver</code> 基类或继承现有应用的特定驱动程序，如 <code v-pre>LaravelValetDriver</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Valet<span class="token punctuation">\</span>Drivers<span class="token punctuation">\</span>LaravelValetDriver</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">LocalValetDriver</span> <span class="token keyword">extends</span> <span class="token class-name">LaravelValetDriver</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 确定驱动程序是否给请求提供服务。</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$sitePath</span></span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$siteName</span></span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$uri</span></span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">bool</span></span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">serves</span><span class="token punctuation">(</span><span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token variable">$uri</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token constant boolean">true</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 获取对应用程序的前端控制器的完全解析路径。</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$sitePath</span></span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$siteName</span></span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$uri</span></span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">string</span></span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">frontControllerPath</span><span class="token punctuation">(</span><span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token variable">$uri</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$sitePath</span><span class="token operator">.</span><span class="token string single-quoted-string">'/public_html/index.php'</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="其他-valet-命令" tabindex="-1"><a class="header-anchor" href="#其他-valet-命令"><span>其他 Valet 命令</span></a></h2>
<table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code v-pre>valet list</code></td>
<td>列出所有 Valet 命令</td>
</tr>
<tr>
<td><code v-pre>valet forget</code></td>
<td>从「驻留」目录运行此命令，将其从驻留目录列表中删除。</td>
</tr>
<tr>
<td><code v-pre>valet log</code></td>
<td>查看 Valet 服务记录的日志列表。</td>
</tr>
<tr>
<td><code v-pre>valet paths</code></td>
<td>查看所有「驻留」的路径。</td>
</tr>
<tr>
<td><code v-pre>valet restart</code></td>
<td>重启 Valet 守护进程。</td>
</tr>
<tr>
<td><code v-pre>valet start</code></td>
<td>启动 Valet 守护进程。</td>
</tr>
<tr>
<td><code v-pre>valet stop</code></td>
<td>停止 Valet 守护进程。</td>
</tr>
<tr>
<td><code v-pre>valet trust</code></td>
<td>为 Brew 和 Valet 添加 sudoers 文件，使 Valet 输入命令的时候不需要输入密码。</td>
</tr>
<tr>
<td><code v-pre>valet uninstall</code></td>
<td>卸载 Valet：显示手动卸载的说明。 传递 <code v-pre>--force</code> 选项来主动删除 Valet 的所有资源。</td>
</tr>
</tbody>
</table>
<h2 id="valet-目录和文件" tabindex="-1"><a class="header-anchor" href="#valet-目录和文件"><span>Valet 目录和文件</span></a></h2>
<p>你可能会发现以下目录和文件信息对排查你的 Valet 环境故障问题很有帮助：</p>
<h4 id="config-valet" tabindex="-1"><a class="header-anchor" href="#config-valet"><span><code v-pre>~/.config/valet</code></span></a></h4>
<p>包含 Valet 所有的配置，你可能希望对此文件夹进行备份。</p>
<h4 id="config-valet-dnsmasq-d" tabindex="-1"><a class="header-anchor" href="#config-valet-dnsmasq-d"><span><code v-pre>~/.config/valet/dnsmasq.d/</code></span></a></h4>
<p>此目录包含 DNSMasq 的配置。</p>
<h4 id="config-valet-drivers" tabindex="-1"><a class="header-anchor" href="#config-valet-drivers"><span><code v-pre>~/.config/valet/Drivers/</code></span></a></h4>
<p>此目录包含 Valet 的驱动，驱动判断如何为特定的 framework/CMS 提供服务。</p>
<h4 id="config-valet-extensions" tabindex="-1"><a class="header-anchor" href="#config-valet-extensions"><span><code v-pre>~/.config/valet/Extensions/</code></span></a></h4>
<p>此目录包括自定义的 Valet 扩展和指令。</p>
<h4 id="config-valet-nginx" tabindex="-1"><a class="header-anchor" href="#config-valet-nginx"><span><code v-pre>~/.config/valet/Nginx/</code></span></a></h4>
<p>此目录包含所有 Valet 的 Nginx 站点配置，当运行 <code v-pre>install</code>、<code v-pre>secure</code>、<code v-pre>tld</code> 指令时会重建这些配置文件。</p>
<h4 id="config-valet-sites" tabindex="-1"><a class="header-anchor" href="#config-valet-sites"><span><code v-pre>~/.config/valet/Sites/</code></span></a></h4>
<p>此目录包含所有 <a href="#the-link-command">链接项目</a>的符号链接。</p>
<h4 id="config-valet-config-json" tabindex="-1"><a class="header-anchor" href="#config-valet-config-json"><span><code v-pre>~/.config/valet/config.json</code></span></a></h4>
<p>此文件是 Valet 的主要配置文件。</p>
<h4 id="config-valet-valet-sock" tabindex="-1"><a class="header-anchor" href="#config-valet-valet-sock"><span><code v-pre>~/.config/valet/valet.sock</code></span></a></h4>
<p>这个文件是 Valet 中 Nginx 安装使用的 PHP-FPM 套接字，只有在 PHP 正常运行的情况下，它才会存在。</p>
<h4 id="config-valet-log-fpm-php-www-log" tabindex="-1"><a class="header-anchor" href="#config-valet-log-fpm-php-www-log"><span><code v-pre>~/.config/valet/Log/fpm-php.www.log</code></span></a></h4>
<p>此文件是 PHP 错误的用户日志。</p>
<h4 id="config-valet-log-nginx-error-log" tabindex="-1"><a class="header-anchor" href="#config-valet-log-nginx-error-log"><span><code v-pre>~/.config/valet/Log/nginx-error.log</code></span></a></h4>
<p>此文件是 Nginx 错误的用户日志。</p>
<h4 id="usr-local-var-log-php-fpm-log" tabindex="-1"><a class="header-anchor" href="#usr-local-var-log-php-fpm-log"><span><code v-pre>/usr/local/var/log/php-fpm.log</code></span></a></h4>
<p>此文件是 PHP-FPM 错误的系统日志。</p>
<h4 id="usr-local-var-log-nginx" tabindex="-1"><a class="header-anchor" href="#usr-local-var-log-nginx"><span><code v-pre>/usr/local/var/log/nginx</code></span></a></h4>
<p>此目录包含 Nginx 的访问和错误日志。</p>
<h4 id="usr-local-etc-php-x-x-conf-d" tabindex="-1"><a class="header-anchor" href="#usr-local-etc-php-x-x-conf-d"><span><code v-pre>/usr/local/etc/php/X.X/conf.d</code></span></a></h4>
<p>此目录包含用于各种 PHP 配置设置的 <code v-pre>*.ini</code> 文件</p>
<h4 id="usr-local-etc-php-x-x-php-fpm-d-valet-fpm-conf" tabindex="-1"><a class="header-anchor" href="#usr-local-etc-php-x-x-php-fpm-d-valet-fpm-conf"><span><code v-pre>/usr/local/etc/php/X.X/php-fpm.d/valet-fpm.conf</code></span></a></h4>
<p>此文件是 PHP-FPM 池配置文件。</p>
<h4 id="composer-vendor-laravel-valet-cli-stubs-secure-valet-conf" tabindex="-1"><a class="header-anchor" href="#composer-vendor-laravel-valet-cli-stubs-secure-valet-conf"><span><code v-pre>~/.composer/vendor/laravel/valet/cli/stubs/secure.valet.conf</code></span></a></h4>
<p>该文件是默认的 Nginx 配置文件，用来为你的网站生成 SSL 证书。</p>
<h3 id="磁盘访问权限" tabindex="-1"><a class="header-anchor" href="#磁盘访问权限"><span>磁盘访问权限</span></a></h3>
<p>从 maxOS 10.14 开始，<a href="https://manuals.info.apple.com/MANUALS/1000/MA1902/en_US/apple-platform-security-guide.pdf" target="_blank" rel="noopener noreferrer">访问部分文件和目录默认受限</a>。这些限制包括桌面，文档，以及下载目录。此外，网络磁盘和可卸载磁盘访问也受限。因此，Valet 推荐你不要将网站目录放在这些受保护的地方。</p>
<p>尽管如此，如果你希望在上述这些地方里提供网站服务，则要给予 Nginx「完全磁盘访问权限」。否则，Nginx 可能会出现服务器错误或其他不可预知的行为，尤其是访问静态资源时。通常来说，macOS 会自动询问你是否给予 Nginx 对这些地方的完全访问权限。或者，你也可以通过 <code v-pre>系统偏好设置</code> &gt; <code v-pre>安全性与隐私</code> &gt; <code v-pre>隐私</code>，然后选择 <code v-pre>完全磁盘访问权限</code> 手动设置。接下来，在主窗口中启用所有 <code v-pre>nginx</code> 选项。</p>
<blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/10.x/valet/14918" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/10.x/va...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/10.x/valet/14918" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/10.x/va...</a></p>
</blockquote>
</div></template>


